<template>
	<view class="page" :style="themeColor">
		<view class="flex benben-position-layout flex flex-wrap align-center aboutUs_flex_0"
			:style="{height:(64+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
			<view class='flex flex-wrap align-center justify-between flex-sub aboutUs_fd0_0'>
				<view class='flex flex-wrap align-center aboutUs_fd0_0_c2' @tap.stop="handleJumpDiy" data-type="back" data-url="1">
					<text class='fu-iconfont2  aboutUs_fd0_0_c0_c0' @tap.stop="handleJumpDiy" data-type="back"
						data-url="1">&#xE794;</text>
				</view>
				<view class='flex flex-wrap align-stretch justify-center flex-sub'>
					<text class='aboutUs_fd0_0_c1_c0'>蓝牙连接</text>
				</view>
				<view class='flex flex-wrap align-center aboutUs_fd0_0_c2'>
				</view>
			</view>

		</view>
		<view :style="{height: (64+StatusBarRpx)+'rpx'}"></view>

		<view class="list">
			<view class="item" v-for="(item, index) in list" :key="index">
				<view class="item_left">
					<image :src='STATIC_URL+"110.png"' mode="aspectFill"></image>
					<text>
						<text>{{item.name ? item.name : 'N/A'}}</text>
						<text class="item_left_1">{{item.address}}</text>
					</text>
				</view>
				<view class="item_right">
					<view class="lianjie" @tap.stop="connect(item.address)">连接</view>
				</view>
			</view>
		</view>

	</view>
</template>
<script>
	export default {
		components: {},


		data() {
			return {
				list: [],  // 蓝牙设备列表
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},
		},
		watch: {},
		onLoad(options) {
			this.searchBluetooth();
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {
			
		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {
			this.searchBluetooth();
		},
		onReachBottom(e) {
			
		},
		onPageScroll(e) {

		},
		methods: {
			// 搜索蓝牙
			searchBluetooth() {
				this.$printer.searchBle(res => {
					console.log(res);
					if (res.code == 1) {
						if (!res.name) {
							res.name = "";
						}
						this.list.push(res);
					} else {
						this.$message.info('蓝牙搜索失败，请重试');
					}
				})
				uni.stopPullDownRefresh();
			},
			// 连接蓝牙
			connect(address) {
				uni.showLoading({
					title: '连接中'
				})
				console.log(address);
				this.$printer.connectBle(res => {
					uni.hideLoading();
					console.log(res);
					this.$message.info('连接成功');
					setTimeout(() => {
						uni.navigateBack();
					}, 500)
				},{
					address: address
				})
			},
		}
	};
</script>
<style lang="scss" scoped>
	.list {
		padding: 0 25rpx;
		.item {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding:  12rpx 0;
			.item_left {
				display: flex;
				align-items: center;
				font-size: 25rpx;
				image {
					width: 28rpx;
					height: 28rpx;
					margin-right: 16rpx;
				}
				.item_left_1 {
					font-size: 20rpx;
					margin-left: 8rpx;
					color: #999;
				}
			}
			.item_right {
				.lianjie {
					background: #4087FD;
					width: 120rpx;
					height: 42rpx;
					border-radius: 8rpx;
					line-height: 42rpx;
					text-align: center;
					font-size: 18rpx;
					color: #fff;
				}
			}
		}
	}
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: var(--benbenbgColor1);
		background-size: 100% auto !important;
	}

	.aboutUs_flex_0 {
		background: #fff;
		width: 100%;
		height: 64rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.aboutUs_fd0_0_c2 {
		width: 50rpx;
		height: 50rpx;
	}

	.aboutUs_fd0_0_c1_c0 {
		font-size: 25rpx;
		font-weight: 500;
		color: #333;
		line-height: 64rpx;
	}

	.aboutUs_fd0_0_c0_c0 {
		font-size: 25rpx;
		font-weight: 500;
		color: #333;
	}

	.aboutUs_fd0_0 {
		margin: 0rpx 25rpx 0rpx 25rpx;
	}

	.aboutUs_fd1_1_c0 {
		font-weight: 400;
		color: #333333;
		font-size: 20rpx;
		margin-top: 25rpx;
	}

	.aboutUs_fd1_0 {
		width: 150rpx;
		height: 150rpx;
		border-radius: 16rpx;
		margin: 98rpx 0rpx 0rpx 0rpx;
	}

	.aboutUs_flex_2 {
		width: 100%;
		// height: 168rpx;
		overflow: hidden;
		z-index: 10;
		bottom: calc(0rpx + var(--window-bottom));
		padding-bottom: 35rpx;
	}

	.aboutUs_fd2_1 {
		margin: 8rpx 0rpx 0rpx 0rpx;
		color: #BFBFBF;
		font-size: 20rpx;
		font-weight: 400;
		line-height: 40rpx;
	}

	.aboutUs_fd2_0 {
		color: #BFBFBF;
		font-size: 20rpx;
		font-weight: 400;
		line-height: 40rpx;
	}
</style>